package com.future.mayi.fragment;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.future.mayi.R;
import com.future.mayi.activity.BasePage;
import com.future.mayi.view.SampleCoverVideo;


/**
 * Created by 周大虎 on 2017/3/6.
 */

public class GoodsVideoPage extends BasePage {

    private String videoUrl, imageUrl;
    private Context context;
    private SampleCoverVideo videoView;

    public GoodsVideoPage(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    protected View initLayout() {
        return setContentView(R.layout.item_title_carousel_video);
    }

    @Override
    protected void initView() {
        videoView = (SampleCoverVideo) findViewById(R.id.video_view);
    }

    @Override
    protected void initDates() {
        if (imageUrl != null)
            videoView.loadCoverImage(imageUrl);
        if (videoUrl != null)
            videoView.setUpLazy(videoUrl, true, null, null, null);
        //增加title
        videoView.getTitleTextView().setVisibility(View.GONE);
        //设置返回键
        videoView.getBackButton().setVisibility(View.GONE);
        //设置全屏按键功能
        videoView.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                videoView.startWindowFullscreen(context, false, true);
            }
        });
        //防止错位设置
        videoView.setPlayTag(String.valueOf(hashCode()));
        videoView.setPlayPosition(0);
        //是否根据视频尺寸，自动选择竖屏全屏或者横屏全屏
        videoView.setAutoFullWithSize(true);
        //音频焦点冲突时是否释放
        videoView.setReleaseWhenLossAudio(false);
        //全屏动画
        videoView.setShowFullAnimation(true);
        //小屏时不触摸滑动
        videoView.setIsTouchWiget(false);
    }

    @Override
    protected void initListener() {

    }


    public void setData(String videoUrl, String imageUrl) {
        this.videoUrl = videoUrl;
        this.imageUrl = imageUrl;
        if (videoView == null) return;
        videoView.loadCoverImage(imageUrl);
        videoView.setUpLazy(videoUrl, true, null, null, null);
    }
}
